
from ReadData import Readdata
from sklearn.metrics import precision_score


from sklearn.ensemble import BaggingClassifier

class Bagging(Readdata):

    def __init__(self):
        super(Bagging, self).__init__()


    def trainAndtest(self, X_train, y_train, X_test, y_test):
        clf = BaggingClassifier(n_estimators=50)
        clf.fit(X_train, y_train)
        y_pred = clf.predict(X_test)
        print("自助聚合算法")
        print("训练集得分:", clf.score(X_train, y_train))
        print("测试集得分:", clf.score(X_test, y_test))
        print("查准率:", precision_score(y_test, y_pred))
